#include "client.h"
#define MAXSIZE 1024


void showmenu(void) {
    printf("*****************************\n");
    printf("*************cd**************\n");
    printf("*************ls**************\n");
    printf("************rmdir************\n");
    printf("************mkdir************\n");
    printf("*************pwd*************\n");
    printf("********puts filename********\n");
    printf("********gets filename********\n");
    printf("********rm filename**********\n");
    printf("*****************************\n");
}
//接收确定个字节的数据
int recvn(int sockfd, void* buff, int len) {
    int left = len;
    char* pbuf = (char*)buff;
    int ret = 0;
    while (left > 0) {
        ret = recv(sockfd, pbuf, left, 0);
        if (ret < 0) {
            perror("recv");
            break;
        } else if (ret == 0) {
            break;
        }
        pbuf += ret;
        left -= ret;
    }
    return len - left;
}

//发送确定个数据
int sendn(int sockfd, const void* buff, int len) {
    int left = len;
    const char* pbuf = (char*)buff;
    int ret = 0;
    while (left > 0) {
        ret = send(sockfd, pbuf, left, 0);
        if (ret == -1) {
            perror("send");
            return -1;
        }
        pbuf += ret;
        left -= ret;
    }
    return len - left;
}
// 解析命令行输入，分离命令和参数
void parseInput(char* input, char** args, char** content) {
    *args = strtok(input, " \n");
    *content = strtok(NULL," \n");    
}



void rmdirCommand(client_task_t * task){

}


void doTask(client_task_t * task){
    switch (task->train.type) {
        case CMD_TYPE_PWD :
            //处理pwd命令
            pwdCommand(task);
            break;
        case CMD_TYPE_LS:
            // 处理 ls 命令
            printf("Receiving directory listing ...\n");
            lsCommand(task);
            printf("Listing directory contents ...\n");
            break;
        case CMD_TYPE_CD:
            // 处理 cd 命令
            printf("Changing directory ...\n");
            break;
        case CMD_TYPE_MKDIR:
            // 处理 mkdir 命令
            /* mkdirCommand(task); */
            printf("Creating directory ...\n");
            break;
        case CMD_TYPE_RMDIR:
            // 处理 rmdir 命令
            /* rmdirCommand(task); */
            printf("Removing directory ...\n");
            break;
        case CMD_TYPE_PUTS:
            putsCommand(task);
            printf("send %s over\n", task->train.buff);
            break;
        case CMD_TYPE_GETS:
            // 处理 gets 命令
            /* getsCommand(task); */
            getsCommand(task);
            printf("Receiving file ...\n");
            break;
        case CMD_TYPE_TREE:
            // 处理 tree 命令
            treeCommand(task);
            printf("Receiving tree ...\n");
            break;
        default:
            // 可选：处理未预期的命令类型
            printf("Unhandled command type.\n");
            break;
        }
}



